//
//  ChangeBIViewController.m
//  ForengnMenu
//
//  Created by @-@ on 16/1/14.
//  Copyright © 2016年 余旺. All rights reserved.
//

#import "ChangeBIViewController.h"
#import "ChangeBICollectionViewCell.h"
#import "ChangeBICollectionReusableView.h"


@interface ChangeBIViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property NSArray * images;

@end

@implementation ChangeBIViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
 self.images = @[@"Icon_ background@2x",@"Icon_bg@2x",@"Icon_bg6",@"Icon_bg1",@"Icon_bg2",@"Icon_bg3",@"Icon_bg4",@"Icon_bg5"];
}

//每一节返回多少行
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return self.images.count;
}

//渲染每一个items
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * identifier = @"cell";
    ChangeBICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath ];
    
    cell.changeBI.image = [UIImage imageNamed:self.images[indexPath.row]];
    
    
    return cell;
}

//节头
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    
    ChangeBICollectionReusableView * view = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"header" forIndexPath:indexPath];
    
    view.myREusableLabel.text = @"换张你喜欢的图片吧!";
    
    view.backgroundColor = [UIColor whiteColor];
    
    return view;
}

//返回每一个item的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    return CGSizeMake(95,145);
    
}

//设置边界间隙
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    //上、左、下、右
    return UIEdgeInsetsMake(10, 5, 10, 5);
}



-(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:self.images[indexPath.row]]];

    [collectionView deselectItemAtIndexPath:indexPath animated:YES];
    
}


- (IBAction)returnBnt:(id)sender {
    
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}


@end
